const {fork} = require("child_process");

var childProcess = fork("fork-child.js");

var index = 0;
var intervalId = setInterval(() => {
    childProcess.send("this is a message from parent process");
    index++;
    if(index == 10){
        clearInterval(intervalId);
    }
},2000);

childProcess.send("this is a process-message");//向子进程发送消息

childProcess.on("message",(chunk) => {
    console.log(chunk);
})